#pragma once
#include "CSocket.h"
namespace CSocket
{
	SOCKET Socket()
	{
		return socket(AF_INET, SOCK_STREAM, 0);;
	}
	bool Bind(SOCKET sock, const char* ip, int port)
	{
		SOCKADDR_IN sAddr;
		sAddr.sin_addr.S_un.S_addr = inet_addr(ip);//TODO
		sAddr.sin_family = AF_INET;
		sAddr.sin_port = htons(port);
		return  SOCKET_ERROR != ::bind(sock, (sockaddr*)&sAddr, sizeof(sAddr));
	}
	bool Listen(SOCKET sock)
	{
		return SOCKET_ERROR != listen(sock, 128);
	}
	SOCKET Accept(SOCKET sock, SOCKADDR_IN& clientAddr, int& addrLen)
	{
		return accept(sock, (sockaddr*)&clientAddr, &addrLen);
	}
	void Close(SOCKET sock)
	{
		closesocket(sock);
	}
	int Recv(SOCKET sock, char* buf, int len)
	{
		return recv(sock, buf, len, 0);
	}
	int Send(SOCKET sock, const char* buf, int len)
	{
		return send(sock, buf, len, 0);
	}

}